﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public enum CameraFollowStyle
{
    /// <summary>
    /// 自由
    /// </summary>
    Freedom = 0,
    /// <summary>
    /// 上帝视角
    /// </summary>
    God,
    /// <summary>
    /// 45度视角
    /// </summary>
    BI45,
    /// <summary>
    /// 第三人称视角
    /// </summary>
    ThirdPersion,
    Count,
}

public class CameraBtnCtr : MonoBehaviour
{
    public Camera camera;
    public Text projeTex;
    public Dropdown dropdown;
    public UGUIToggle projection, rotate;
    public Button reset;

    public CameraController contr;
    string[] dropName = { "Freedom","God","BI45","ThirdPersion"};
    private void InitCameraFollowStyleDropdown()
    {
        dropdown.options.Clear();
        Dropdown.OptionData tempData;
        int count = (int)CameraFollowStyle.Count;
        for (int i = 0; i < count; i++)
        {
            tempData = new Dropdown.OptionData();
            tempData.text = dropName[i];
            dropdown.options.Add(tempData);
        }
    }

    private void OnEnable()
    {
        InitCameraFollowStyleDropdown();
        projection.onValueChangedEvent = OnProjectionToggle;
        rotate.onValueChangedEvent = OnRotateToggle;
    }

    private void OnProjectionToggle(object obj, bool value)
    {
        if (value == true)//透视  perspective
        {
            projeTex.text = "Pers";
            rotate.gameObject.SetActive(true);
            reset.gameObject.SetActive(true);
        }
        else // 正交 orthographic
        {
            projeTex.text = "Orth";
            rotate.gameObject.SetActive(true);
            reset.gameObject.SetActive(false);
            dropdown.gameObject.SetActive(false);
        }
        SetCameraProjectStyle(value);
    }
    private void SetCameraProjectStyle(bool isPers)
    {
        if (isPers == true)
        {
            camera.orthographic = false;
        }
        else
        {
            camera.orthographic = true;
            camera.orthographicSize = 3;
        }
    }
    private void OnRotateToggle(object obj, bool value)
    {
        if (value == true) //拖拽旋转
        {
            dropdown.gameObject.SetActive(false);
        }
        else // 不能拖拽旋转 复位 ， 选择一个相机跟随模式
        {
            dropdown.gameObject.SetActive(true);
        }
        contr.SetRotate(value);
    }
}
